package com.hspedu.codeblock_;

public class CodeBlock01 {
    public static void main(String[] args) {
        Movie movie1 = new Movie("你好，李焕英");
        System.out.println("============");
        Movie movie2 = new Movie("你好，李焕英", 34);
    }
}


class Movie {
    private String name;
    private double price;
    private String director;

    //不管调用哪个构造器创建对象，都会先调用代码块内容
    //代码块调用的顺序优先于构造器
    {
        System.out.println("电影屏幕打开...");
        System.out.println("广告开始...");
        System.out.println("电影正在开始...");
    }

    public Movie(String name, double price, String director) {
        System.out.println("Movie(String name, double price, String director) 被调用...");
        this.name = name;
        this.price = price;
        this.director = director;
    }

    public Movie(String name, double price) {
        System.out.println("Movie(String name, double price) 被调用...");
        this.name = name;
        this.price = price;
    }

    public Movie(String name) {
        System.out.println("Movie(String name) 被调用...");
        this.name = name;
    }
}
